package com.example.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Slf4j
@Aspect
@Component
public class AllAspect {
    @Pointcut("execution(* com.example.service.*.*(..))")
    private void pointCut() {}

    @Before("pointCut()")
    public void before(JoinPoint joinPoint) {
        log.info("before method invoked ...");
    }
    @Around("pointCut()")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        log.info("around method invoked before ...");
        // 调用目标对象的原始方法来执行
        Object proceed = joinPoint.proceed();
        log.info("around method invoked after ...");
        return proceed;
    }
    @After("pointCut()")
    public void after(JoinPoint joinPoint) {
        log.info("after method invoked ...");
    }

    @AfterReturning("pointCut()")
    public void afterReturning(JoinPoint joinPoint) {
        log.info("afterReturning method invoked ...");
    }
    @AfterThrowing("pointCut()")
    public void afterThrowing(JoinPoint joinPoint) {
        log.info("afterThrowing method invoked ...");
    }
}